package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分类管理控制层
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService CategoryService;
    /**
     * 新增分类
     * @return
     */
    @PostMapping
    public R addCategory(@RequestBody  Category category) {
        return CategoryService.addCategory(category);
    }

    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R page(Integer page,Integer pageSize){

        return CategoryService.categoryPage(page,pageSize);
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public R deleteById(Long id){
        return CategoryService.deleteById(id);
    }

    /**
     * 修改分类
     * @param category
     * @return
     */
    @PutMapping
    public R modify(@RequestBody Category category){

        return CategoryService.modify(category);
    }


    /**
     * 根据条件查询
     * @param category
     * @return
     */
    @GetMapping("/list")
    public R list(Category category){
        return CategoryService.findList(category);
    }
}